package com.owen.springboot.smartparkingms.common.config;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.DriverManager;

/**
 * 金额格式化
 */
public class BigDecimalSerialize extends JsonSerializer<BigDecimal> {

    /**
     * 序列化操作
     * @param value
     * @param gen
     * @param serializerProvider
     * @throws IOException
     */
    @Override
    public void serialize(BigDecimal value, JsonGenerator gen, SerializerProvider serializerProvider) throws IOException {
        if (value != null && !"".equals(value)) {
            gen.writeString(value.setScale(2, BigDecimal.ROUND_HALF_DOWN) + "");
        } else {
            gen.writeString(value + "");

        }
    }
}